/*
 * This file is part of the Android Dimensions Editor Project: http://code.google.com/p/android-dimension-editor/
 *  
 * Copyright (c) 2013 Rick Falck
 *  
 * This code is licensed under the terms of the Apache License Version 2.0.
 * You may use this code according to the license.
 *
 * The terms of the license can be found in the root directory of this project's repository as well as at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under these Licenses is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See each License for the specific language governing permissions and
 * limitations under that License.
 */

package model;

import javafx.scene.control.TextField;

/**
 * <b>public abstract class ItemTextField extends TextField</b>
 * <p>
 * This class is the base class for a name, item, or comment.
 * 
 * @author Rick Falck
 */
public abstract class ItemTextField extends TextField {
	protected String mOriginalString;

	public ItemTextField(String value) {
		super();
		mOriginalString = value;
		setText(value);
		this.getStylesheets().add("application/application.css");
		this.getStyleClass().add(getMyStyle());
	}
	
	abstract String getMyStyle();

	@Override
	public String toString() {
		return mOriginalString;
	}

	public boolean isValueChanged() {
		return this.getText().trim().toLowerCase().equalsIgnoreCase(mOriginalString);
	}

	@Override
	public boolean equals(Object other) {
		ItemTextField otherName = null;
		try {
			otherName = (ItemTextField) other;
		} catch (ClassCastException e) {
			return false;
		}
		return this.mOriginalString.equalsIgnoreCase(otherName.mOriginalString);
	}

	public boolean isNameChanged() {
		return !this.getText().trim().toLowerCase().equals(mOriginalString);
	}
	
	public void setToCurrentName() {
		mOriginalString = getText().trim().toLowerCase();
	}

	public String getOriginalString() {
		return mOriginalString;
	}

	public void setOriginalString(String originalString) {
		mOriginalString = originalString;
	}
}
